package com.test.servlet;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Iterator;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;

import com.test.utils.IdUtils;
import com.test.utils.JdbcUtils;

/**
 * Servlet implementation class UpdjingdianServlet
 * 更新景点信息
 */
public class UpdjingdianServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public UpdjingdianServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		System.out.println("我来了。。。");
		request.setCharacterEncoding("utf-8");
        response.setContentType("text/html");
        response.setCharacterEncoding("UTF-8");
        PrintWriter out = response.getWriter();
        String id = request.getParameter("id");
        String yiji = request.getParameter("yiji");
        String erji = request.getParameter("erji");
        String sanji = request.getParameter("sanji");
        String name = request.getParameter("name");
        String jianjie = request.getParameter("jianjie");
        String lishi = request.getParameter("lishi");
        String wenhua = request.getParameter("wenhua");
        String techang = request.getParameter("techang");
       /* System.out.println("id:" + id);
        System.out.println("yiji:" + yiji);
        System.out.println("erji:" + erji);
        System.out.println("sanji:" + sanji);
        System.out.println("name:" + name);
        System.out.println("jianjie:" + jianjie);
        System.out.println("lishi:" + lishi);
        System.out.println("wenhua:" + wenhua);
        System.out.println("techang:" + techang);*/
        //保存信息scenic_spot
        String sql = "UPDATE scenic_spot SET yiji = '"+yiji+"', erji = '"+erji+"',sanji= '"+sanji+"',name='"+name+"',jianjie='"+jianjie+"',lishi='"+lishi+"',wenhua='"+wenhua+"',techang='"+techang+"'" + 
              "WHERE id ='"+id+"'";
        JdbcUtils jdbcUtils = new JdbcUtils();
        try {
			Connection conn = jdbcUtils.getConnection();
			Statement stmt = conn.createStatement();
			int dept = stmt.executeUpdate(sql);
			if(dept==1) {
				out.println("修改成功！！");
				return;
			}else {
				out.println("修改失败！！");
				return;
			}
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
